package cn.t.keycloak.demo.mfa.sms.action;

import lombok.extern.slf4j.Slf4j;
import org.keycloak.Config;
import org.keycloak.authentication.RequiredActionFactory;
import org.keycloak.authentication.RequiredActionProvider;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;

/**
 * 用户登录后的必须操作
 * @author 陶敏麒
 * @date 2023/11/17 9:12
 */
@Slf4j
public class SmsOptMfaAuthRequiredActionFactory implements RequiredActionFactory {

    private static final SmsOptMfaAuthRequiredAction SINGLETON = new SmsOptMfaAuthRequiredAction();


    @Override
    public String getDisplayText() {
        return "PHONE SMS(手机验证码)";
    }

    @Override
    public RequiredActionProvider create(KeycloakSession keycloakSession) {
        return SINGLETON;
    }

    @Override
    public void init(Config.Scope scope) {
        log.info(">>SmsAuthRequiredActionFactory用户必须配置手机号码SPI已加载");
    }

    @Override
    public void postInit(KeycloakSessionFactory keycloakSessionFactory) { }

    @Override
    public void close() {}

    @Override
    public String getId() {
        return SmsOptMfaAuthRequiredAction.PROVIDER_ID;
    }
}
